var querystring = require('querystring')
var url = require('url')

var bodyParser = function (req, res, next) {
    if (req.method == 'GET') {
        req.body = querystring.parse(url.parse(req.url).query)
        next()
    } else {
        var str = ''
        req.on('data', (chunk) => {
            str += chunk
        })
        req.on('end', () => {
            if (str!=undefined) {
                console.log(str)
                req.body = JSON.parse(str)
                console.log(req.body)
                next()
            }else{
                console.log(222)
                req.body=''
                next()
            }
        })
    }
}

module.exports = bodyParser